<template>
  <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
    <!--<FormItem>-->
    <Row>
      <FormItem prop="title" label="日志标题:">
        <Input v-model="formValidate.title" placeholder="请输入文章标题"></Input>
      </FormItem>
    </Row>
    <Row>
      <FormItem prop="account" label="日志内容:">
        <Input v-model="formValidate.account" type="textarea" :rows="10" placeholder="请输入文章内容"></Input>
      </FormItem>
    </Row>
    <Row>
      <Col span="10">
      <FormItem label="图片:" prop="picture">
        <upload ref="picref"></upload>
      </FormItem>
      </Col>

      <Col span="10">

      </Col>
    </Row>

    <FormItem>

      <Button type="primary" @click="handleSubmit()">提交</Button>
      <Button type="ghost" @click="handleReset('formValidate')" style="margin-left: 8px">重置</Button>
      <Button type="primary" @click="fanhui()" style="margin-left: 8px">返回</Button>
    </FormItem>

  </Form>
</template>

<script>
  import upload from  '../utils/share_upload_pic';
  export default {
    data () {
      return {
        showLogger:'showLogger',
        formValidate: {
          id:'',
          title: '',
          account: '',
          picture: '',
          state:'',
        },
        ruleValidate: {
          title: [
            { required: true, message: '标题不能为空！', trigger: 'blur' }
          ],
          account: [
            { required: true, message: '内容不能为空！', trigger: 'blur' }
          ],
        }
      }
    },
    created(){
      this.loadinginfo();
    },
    components: {
      upload
    },
    methods: {
      loadinginfo(){
        let self=this;
        let id= '';
        if(self.$route.query.id){
          id=self.$route.query.id;
          this.$http.get("/api/logger/selectById?id="+id)
            .then(response => {
              console.log("response.data.data....",response.data);
              self.formValidate=response.data;
            }, response => {
              console.log("获取信息失败");
            })
        }

      },
      fanhui(){
        this.$router.replace({ path: '/showLogger'});
      },
      handleSubmit () {
        let self=this;
        console.log("self.formValidate====",self.formValidate);
//        console.log("file......................",this.$refs.picref.file);
//        self.formValidate.picurl=self.$refs.picref.file.imgName;
        this.$http.post("/api/logger/save/",self.formValidate)
          .then(response => {
            console.log("response====",response);
            if(response.data.code==500){
              alert("保存成功！");
              this.$router.replace({ path: '/showLogger'})
            }
            else{
              alert("保存失败！");

            }
          }, response => {
            console.log("获取信息失败");
            alert("保存失败！");
          })
      },
      handleReset (name) {
        this.$refs[name].resetFields();
      }
    }
  }
</script>
